package com.letv.so.util;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.letv.so.constants.PayPlatFormEnum;

public class ThreadLocalUtil {
    private static final ThreadLocal<Map<String, String>> tl = new ThreadLocal<Map<String, String>>();

    public static void setCityInfo(String cityInfo) {
        tl.get().put("cityInfo", cityInfo);
    }
    
    public static void calculatePlatform(String from) {
        String ph = "";
        if (StringUtils.isNotBlank(from)) {
            if (from.toUpperCase().startsWith(PayPlatFormEnum.TV.getKey())) {
                ph = PayPlatFormEnum.TV.getKey();
            } else if (from.toUpperCase().startsWith(PayPlatFormEnum.WEB.getKey())) {
                ph = PayPlatFormEnum.WEB.getKey();
            } else if (from.toUpperCase().startsWith(PayPlatFormEnum.MOBILE.getKey())) {
                ph = PayPlatFormEnum.MOBILE.getKey();
            } else if (from.toUpperCase().startsWith(PayPlatFormEnum.PAD.getKey())) {
                ph = PayPlatFormEnum.PAD.getKey();
            }
        } else {
            from = "";
        }
        setPh(ph);
        setFrom(from);
    }
    
    public static void setParasMap(Map<String, String> paras) {
        tl.set(paras);
    }
    
    public static String getLang() {
        return tl.get().get("lang");
    }

    public static void setLang(String lang) {
        tl.get().put("lang", lang);
    }

    public static String getFrom() {
        return tl.get().get("from");
    }

    public static void setFrom(String from) {
        tl.get().put("from", from);
    }

    public static String getPh() {
        return tl.get().get("ph");
    }

    static void setPh(String ph) {
        tl.get().put("ph", ph);
    }

}
